#include "VC220.h"
#include "PortUtility.h"

namespace LineDisplayImp
{
	using namespace  PortUtility;

	CLD_VC220::CLD_VC220()
	{

	}

	CLD_VC220::~CLD_VC220()
	{

	}

	void CLD_VC220::Initialize()
	{
		PR_SendStr2Com(m_portInfo.hCom, L"\x1b\x40", 2, m_portInfo.oWrite);
	}

	void CLD_VC220::ClearText()
	{
		PR_SendStr2Com(m_portInfo.hCom, L"\x0c", 1, m_portInfo.oWrite );
	}


	void CLD_VC220::DisplayText(wstring strData, int nAttribute)
	{
		string strCmd;
		if (1 == nAttribute)
		{
			strCmd = "\x1b\x51\x42";
		}
		else
		{
			strCmd = "\x1b\x51\x41" ;
		}

		PR_SendStr2Com(m_portInfo.hCom, (char*)strCmd.c_str(), strCmd.length(), m_portInfo.oWrite);

		string strText = wstring2string(strData);
		PR_SendStr2Com(m_portInfo.hCom, (char*)strText.c_str(), strText.length(), m_portInfo.oWrite);

		PR_SendStr2Com(m_portInfo.hCom, "\x0d", 1, m_portInfo.oWrite);

	}

	void CLD_VC220::DisplayTextAt(int nRow, int nCol, wstring strData, int nAttribute)
	{
		if (nRow == 0 || nRow == 1)
		{
			DisplayText(strData, nRow);
		}
	}

	void CLD_VC220::ScrollTextEx(wstring strData, int nDirection, int nUnits)
	{
		string strCmd = "\x1b\x51\x44";
		PR_SendStr2Com(m_portInfo.hCom, (char*)strCmd.c_str(), strCmd.length(), m_portInfo.oWrite);

		string strText = wstring2string(strData);
		PR_SendStr2Com(m_portInfo.hCom, (char*)strText.c_str(), strText.length(), m_portInfo.oWrite);

		PR_SendStr2Com(m_portInfo.hCom, "\x0d", 1, m_portInfo.oWrite);
	}
}
